function GetRandomNum(Min, Max) {

    var Range = Max - Min;

    var Rand = Math.random();

    return (Min + Math.round(Rand * Range));

}

$(document).ready(function () {

    var tel = getQueryString("tel");
    var openId = getQueryString("openId");
    var appId = getQueryString("appId");

    var roll = function () {
        $(this).unbind('mouseenter').unbind('mouseleave');
        $(this).attr("src", "resource/four2.png");
        if (parseInt($(".coud_num").html()) <= 0) {
            sucessFun("<div class='strong'>谢谢参与!</div><div>今天的抽奖机会已经用完,明天再来吧～</div>");
            var json_error = "error_0";
            return false;
        }

        $(this).unbind("click", roll);

        takePrice(appId, openId, tel, "谢谢参与", "0", function(result) {
            var va = eval('(' + result + ')');
            var angle = 0;
            var zhuan = setInterval(function () {
                angle += 6;
                if (angle >= va.angle) {
                    clearInterval(zhuan);

                    $(".coud_num").html($(".coud_num").html() - 1);
                    $("#tip").bind("click", roll);

                    $("#tip").attr("src", "resource/four1.png");
                    $("#tip").hover(function () {
                        $(this).attr("src", "resource/four1.png");
                    }, function () {
                        $(this).attr("src", "resource/four2.png");
                    });

                    sucessFun("<div class='strong'>" + va.title + "</div><div>" + va.details + "</div>");

                } else {
                    $("#img").rotate(angle);
                }
            }, 15);
        });
    };

    $("#tip").bind("click", roll);

    //获取参数
    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
    }
    function takePrice(appId, opend, tels, prize, grade, successFun) {
        var data =
           {
               appId: appId,
               openId: opend,
               name: "wheel2",
               tel: tels,
               result: prize,
               grade: grade
           };

        $.ajax({
            type: "POST",
            url: "/rest/wheel2/end/wheel2",
            data: data,
            success: successFun
        });
    }
    function sucessFun(content) {
        ymPrompt.succeedInfo(content, 250, 150, null, null);
    }
});
